package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("category")
public class CategoryController {

    private final CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }
    /**
     * 根据id查询分类
     * @param id 分类id
     * @return 分类对象
     */
    @GetMapping("{id}")
    public ResponseEntity<List<CategoryDTO>> queryId(@RequestParam("id") List<Long> id){
        return ResponseEntity.ok(categoryService.queryCategoryByIds(id));
    }
    /**
     * 根据分类id集合查询分类集合
     * @param ids
     * @return
     */
    @GetMapping("list")
    public ResponseEntity<List<CategoryDTO>> queryList(@RequestParam("ids") Long ids){
        return ResponseEntity.ok(categoryService.queryCategoryByParentId(ids));
    }



    /**
     * 根据品牌id查询对应的分类id集合
     * @param bid
     * @return
     *
     * queryCategoryByBrand
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByBrand(@RequestParam("id") Long bid){
        return ResponseEntity.ok(categoryService.queryCategoryByBrand(bid));

    }


    /**
     * 根据父类目id查询子类目的集合
     * @param pid 父类目的id
     * @return 子类目的集合
     *
     * queryCategoryByParentId
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByParentId(@RequestParam("pid") Long pid){
        return ResponseEntity.ok(categoryService.queryCategoryByParentId(pid));
    }
}
